package br.com.timecardforpeon.domain;

import java.util.Date;
import java.util.List;

import br.com.timecardforpeon.domain.contentvalue.DayContentValues;
import br.com.timecardforpeon.domain.contentvalue.TimeCard4PeonContentValues;
import br.com.timecardforpeon.util.Util;

public class Day extends Domain {

	private static final long serialVersionUID = 2063210042740289664L;

	public static final String TABLE_NAME = "day";
	public static final String COLUMN_DAY = "day";
	public static final String COLUMN_NOTES = "notes";
	
	public static final String LIST_DAY_QUERY = "select * from day order by day";
	public static final String GET_BY_DAY_QUERY = "select * from day d where d.day = ?";

	protected Date day;
	protected String notes;
	protected List<Entry> entries;

	public Date getDay() {
		return day;
	}

	public void setDay(Date day) {
		this.day = Util.dateWithoutHourMinuteSecondAndMillisecond(day);
	}

	public String getNotes() {
		return (this.notes != null ? this.notes : "");
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public List<Entry> getEntries() {
		return entries;
	}

	public void setEntries(List<Entry> entries) {
		this.entries = entries;
	}

	@Override
	public TimeCard4PeonContentValues<Day> getContentValues() {
		return new DayContentValues().create(this);
	}

	@Override
	public String getTableName() {
		return TABLE_NAME;
	}

	public static String createTable() {
		return String.format("create table %s (id integer primary key autoincrement, %s text not null unique, %s text null);",
				TABLE_NAME, COLUMN_DAY, COLUMN_NOTES);
	}

	@Override
	public String toString() {
		return Util.dateToString(Util.DATE_FORMAT_FOR_VIEW, this.day);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((day == null) ? 0 : day.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Day other = (Day) obj;
		if (day == null) {
			if (other.day != null)
				return false;
		} else if (!day.equals(other.day))
			return false;
		return true;
	}
}